package converters;

import javax.transaction.Transactional;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import repositories.ComunidadDeVecinosRepository;
import domain.ComunidadDeVecinos;

@Component
@Transactional
public class StringToComunidadConverter implements Converter<String, ComunidadDeVecinos> {

	@Autowired
	ComunidadDeVecinosRepository comunidadDeVecinosRepository;

	public ComunidadDeVecinos convert(String text) {
		ComunidadDeVecinos result;
		int id;

		try {
			id = Integer.valueOf(text);
			result = comunidadDeVecinosRepository.findOne(id);
		} catch (Throwable oops) {
			throw new IllegalArgumentException(oops);
		}

		return result;
	}
}
